package ldh.im.base.service;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import ldh.common.PageResult;
import ldh.im.base.dao.ImTenantDao;
import ldh.im.base.pojo.ImTenant;
import ldh.im.base.pojo.where.ImTenantWhere;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: ldh
 * @date: 2024-03-21 10:36:18
*/
@Service("imTenantService")
public class ImTenantService {

	@Resource
	private ImTenantDao imTenantDao;
	
	@Transactional
	public ImTenant insert(ImTenant imTenant) {
		int n = imTenantDao.insert(imTenant);
		if (n != 1) {
			throw new RuntimeException("ImTenant insert error!");
		}
		return imTenant;
	}
	
	@Transactional
	public ImTenant insertSelective(ImTenant imTenant) {
		int n = imTenantDao.insert(imTenant);
		if (n != 1) {
			throw new RuntimeException("ImTenant insertSelective error!");
		}
		return imTenant;
	}

	@Transactional
	public ImTenant updateById(ImTenant imTenant) {
		int  n = imTenantDao.updateById(imTenant);
		if (n != 1) {
			throw new RuntimeException("ImTenant update error!");
		}
        return imTenant;
     }

	@Transactional
	public ImTenant updateNotNullById(ImTenant imTenant) {
		int  n = imTenantDao.updateNotNullById(imTenant);
		if (n != 1) {
			throw new RuntimeException("ImTenant update error!");
		}
        return imTenant;
     }


    @Transactional
    public void deleteById(Long id) {
		int n = imTenantDao.deleteById(id);
		if (n != 1) {
			throw new RuntimeException("ImTenant delete error!");
		}
    }

	@Transactional(readOnly = true)
	public ImTenant getById(Long id) {
		ImTenant imTenant = imTenantDao.getById(id);
		return imTenant;
    }
    
	@Transactional(readOnly = true)
	public ImTenant getByCode(String code) {
		ImTenant imTenant = imTenantDao.getByCode(code);
		return imTenant;
    }
    
	
	@Transactional(readOnly = true)
	public PageResult<ImTenant> findByImTenantWhere(ImTenantWhere imTenantWhere) {
		long total = imTenantDao.findTotalByImTenantWhere(imTenantWhere);
		List<ImTenant> imageList = new ArrayList<ImTenant>();
		if (total > 0) {
			imageList  = imTenantDao.findByImTenantWhere(imTenantWhere);
		}
		
		return new PageResult<ImTenant>(imTenantWhere, total, imageList);
	}

	@Transactional(readOnly = true)
	public List<ImTenant> getAll(ImTenantWhere tenantWhere) {
		return imTenantDao.findByImTenantWhere(tenantWhere);
	}
}
